﻿using System;

namespace YArchitech.Revit.MEP.Electric.Calculator
{
	internal class CalRoomParam
	{
		public CalRoomParam(RoomData data)
		{
			this.m_RoomData = data;
		}

		public double RoomRCR()
		{
			return 2.5 * this.WallAreaVirtualRoom() / this.RoomArea();
		}

		public double RoomRI()
		{
			return 5.0 / this.RoomRCR();
		}

		public int PCeiling()
		{
			double num = this.PaveCeiling();
			double num2 = this.RoomArea() + this.WallAreaCeiling();
			return this.UnPercent(num * this.RoomArea() / (num2 - num * num2 + num * this.RoomArea()));
		}

		public int PWall()
		{
			return this.UnPercent((this.Percent(this.m_RoomData.WallUpFactor) * (this.WallAreaRoom() - this.m_RoomData.WindowArea) + this.Percent(this.m_RoomData.WindowFactor) * this.m_RoomData.WindowArea) / this.WallAreaRoom());
		}

		public int PFloor()
		{
			double num = this.PaveFloor();
			double num2 = this.RoomArea() + this.WallAreaFloor();
			return this.UnPercent(num * this.RoomArea() / (num2 - num * num2 + num * this.RoomArea()));
		}

		private double HCeiling()
		{
			return this.m_RoomData.RoomHeight - this.m_RoomData.InstallHeight;
		}

		private double HRoom()
		{
			return this.m_RoomData.InstallHeight - this.m_RoomData.WorkHeight;
		}

		private double RoomArea()
		{
			return this.m_RoomData.RoomArea;
		}

		private double WallAreaCeiling()
		{
			return this.m_RoomData.WallPerimeter * this.HCeiling();
		}

		private double WallAreaRoom()
		{
			return this.m_RoomData.WallPerimeter * this.HRoom();
		}

		private double WallAreaVirtualRoom()
		{
			return this.m_RoomData.RoomPerimeter * this.HRoom();
		}

		private double WallAreaFloor()
		{
			return this.m_RoomData.WallPerimeter * this.m_RoomData.WorkHeight;
		}

		private double Percent(double dVar)
		{
			return dVar / 100.0;
		}

		private int UnPercent(double dVar)
		{
			return (int)(dVar * 100.0 + 0.5);
		}

		private double PaveCeiling()
		{
			return (this.Percent(this.m_RoomData.CeilingFactor) * this.RoomArea() + this.Percent(this.m_RoomData.WallUpFactor) * this.WallAreaCeiling()) / (this.RoomArea() + this.WallAreaCeiling());
		}

		private double PaveFloor()
		{
			return (this.Percent(this.m_RoomData.FloorFactor) * this.RoomArea() + this.Percent(this.m_RoomData.WallDownFactor) * this.WallAreaFloor()) / (this.RoomArea() + this.WallAreaFloor());
		}

		private RoomData m_RoomData;
	}
}
